package com.letoken.platform.repo.mall.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.repo.admin.req.mall.AmbListReq;
import com.letoken.platform.repo.admin.req.mall.QueryMallStoreAuditListReq;
import com.letoken.platform.repo.admin.res.mall.AmbListRes;
import com.letoken.platform.repo.admin.res.mall.QueryMallStoreAuditListRes;
import com.letoken.platform.repo.app.po.AppUserIssueRecord;
import com.letoken.platform.repo.mall.po.AppMallAmbassadorRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 推广分红记录 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2023-06-06
 */
public interface AppMallAmbassadorRecordMapper extends BaseMapper<AppMallAmbassadorRecord> {

    Page<AmbListRes> getAmbBonusRecord(@Param("page") Page<AmbListRes> page, @Param("req") AmbListReq req);



    @Select("select IFNULL(sum(total_circulation),0) from app_mall_ambassador_record where create_time >= #{startTime} and create_time < #{endTime}")
    BigDecimal statisticsData(@Param("startTime") String startTime,@Param("endTime") String endTime);



    @Select("select IFNULL(sum(wait_circulation),0) from app_mall_ambassador_record ")
    BigDecimal statisticsWaitCirculation();


    @Select("select * from app_mall_ambassador_record where wait_circulation>0")
    List<AppMallAmbassadorRecord> getWaitCirculation(@Param("userId")Integer userId);

    @Update("update app_mall_ambassador_record set `status` =1,wait_circulation=0")
    int updateAmbassadorRecord();
}
